/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2024-02-03
 * Time: 11:27
 */
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Test3 {
    public static void main(String[] args) {
        String filePath = "韩山师范学院.html";
        countCharacters(filePath);
    }

    public static void countCharacters(String filePath) {
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            int letterCount = 0;
            int digitCount = 0;
            int leftParenthesisCount = 0;
            int rightParenthesisCount = 0;
            boolean linkFound = false;

            String line;
            while ((line = reader.readLine()) != null) {
                for (char c : line.toCharArray()) {
                    if (Character.isLetter(c)) { // 字母
                        letterCount++;
                    } else if (Character.isDigit(c)) { // 数字
                        digitCount++;
                    } else if (c == '(') { // 左圆括号
                        leftParenthesisCount++;
                    } else if (c == ')') { // 右圆括号
                        rightParenthesisCount++;
                    }
                }

                if (line.contains("<a href")) {
                    linkFound = true;
                }
            }

            System.out.println("英文字母个数: " + letterCount);
            System.out.println("数字个数: " + digitCount);
            System.out.println("左圆括号个数: " + leftParenthesisCount);
            System.out.println("右圆括号个数: " + rightParenthesisCount);

            if (leftParenthesisCount == rightParenthesisCount) {
                System.out.println("左圆括号个数与右圆括号个数相等");
            } else {
                System.out.println("左圆括号个数与右圆括号个数不相等");
            }

            if (linkFound) {
                System.out.println("存在超级链接");
            } else {
                System.out.println("不存在超级链接");
            }
        } catch (IOException e) {
            System.out.println("无法打开文件");
            e.printStackTrace();
        }
    }
}